package com.example.test.service;
import com.example.test.entity.Cart;
import com.example.test.entity.Notice;
import com.example.test.mapper.CartMapper;
import org.springframework.stereotype.Service;

@Service
      public class CartService {

      private final CartMapper cartMapper;
      public CartService(CartMapper cartMapper) {
            this.cartMapper = cartMapper;
        }
        public void deleteCart() {
            int rowsAffected = cartMapper.deleteAll();
            if (rowsAffected > 0) {
                // 数据已删除
                System.out.println("Deleted all items from the Cart table.");
            } else {
                // 没有任何数据被删除，可能表是空的
                System.out.println("No items found in the Cart table to delete.");
            }
        }
        public void delete(int itemId) {
            Cart cart=cartMapper.selectById(itemId);
            if (cart != null) {
                cartMapper.deleteById(itemId);
            }
        }
    }

